<?php
    class Menu_Permission_Model extends CI_Model{
        
        function getMainMenuByMemberID($memberID){
            $this->db->select('*');
            $this->db->from('menu_permission');
            $this->db->join('menu', 'menu_permission.MENU_ID = menu.ID');
            $this->db->where('menu_permission.MEMBER_ID', $memberID);
            $this->db->where('menu.PARENT_MENU IS NULL');
            $results = $this->db->get()->result(); 

            return $results;
        }

        function getSubMenuByMemberID($memberID){
            $this->db->select('*');
            $this->db->from('menu_permission');
            $this->db->join('menu', 'menu_permission.MENU_ID = menu.ID');
            $this->db->where('menu_permission.MEMBER_ID', $memberID);
            $this->db->where('menu.PARENT_MENU IS NOT NULL');
            $results = $this->db->get()->result(); 

            return $results;
        }

        function insertPermission($memberID, $menuIDList){
            
            foreach($menuIDList as $menuID){
                echo $menuID->ID;
                $data = array(
                    'MEMBER_ID' => $memberID ,
                    'MENU_ID' => $menuID->ID );
                
                $this->db->insert('menu_permission', $data);
            }
        }
        
        function isWatchVideoEmpty($memberID){
            //Watch Video Menu = 6
            $this->db->from('menu_permission');
            $this->db->where('MEMBER_ID', $memberID);
            $this->db->where('MENU_ID', 6);
            $q = $this->db->get();
            
            if($q->num_rows() > 0){
                return false;
            }else{
                return true;
            }
        }
    }

?>
